import React, {useState} from "react";
import {defaultPagination, paginationTool} from "@/utils/util";

import {useMount, useRequest} from "ahooks";
import {findByBackIntegralList} from "@/services/ant-design-pro/log";
import {getResult} from "@/services/ant-design-pro/attribute";
import {ProTable} from "@ant-design/pro-table";

const walletLogColmunsIntgrall = [{
  title: '编号',
  dataIndex: 'index',
  key: 'index',
  valueType: 'indexBorder',
}, {
  title: "用户姓名",
  key: "name",
  dataIndex: "name",
}, {
  title: "动作",
  key: "stateName",
  dataIndex: "stateName",
  search: false,
}, {
  title: "操作帐户",
  key: "type",
  dataIndex: "type",
  valueType: "select",
  valueEnum: await getResult ( "userswithdrawaltype", 0 ),


}, {
  title: "操作金额",
  key: "integral",
  dataIndex: "integral",
  search: false,
}, {
  title: "当前余额",
  key: "integraln",
  dataIndex: "integraln",
  search: false,
}, {
  title: "详细说明",
  key: "remark",
  dataIndex: "remark",
  search: false,
}, {
  title: "申请时间",
  key: "create_date",
  dataIndex: "create_date",
  valueType: 'dateTime'
}, {
  title: "操作员",
  key: "operatorName",
  dataIndex: "operatorName",
  search: false,
}]

const Page: React.FC = () => {
  const [paginationWalleIntegraltLog, setPaginationWalletIntegralLog] = useState<API.Pagination> ( defaultPagination );


  const {
    run: fetchByBackIntegralLogList,
    refresh: walletIntegralLogRefresh,
    data: walletIntegralLog,
    loading: walletIntegralLogLoading,
  } = useRequest ( findByBackIntegralList, {
    debounceWait: 100,
    manual: true,
  } );

  useMount ( () => {

    fetchByBackIntegralLogList ()

  } );

  return (<ProTable loading={walletIntegralLogLoading}
                    pagination={paginationTool ( paginationWalleIntegraltLog, walletIntegralLog?.data?.total, (data1: API.Pagination) => {
                      console.log ( data1 )
                      setPaginationWalletIntegralLog ( data1 );
                      fetchByBackIntegralLogList ( {...walletIntegralLog, userId: data?.id} );
                    } )} toolBarRender={false} search={true} columns={walletLogColmunsIntgrall}
                    dataSource={walletIntegralLog?.data?.list}></ProTable>)
}


export default Page;
